package com.iwhalecloud.bss.kite.cucc.web.controller.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.cucc.client.api.order.IOrderSignService;
import com.iwhalecloud.bss.kite.cucc.client.dto.cust.CuccContextCustDTO;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.transaction.KiteTransactional;
import com.iwhalecloud.bss.kite.web.context.KiteWebContext;
import com.ztesoft.bss.common.exception.BssException;
import com.ztesoft.bss.common.util.ContextUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 订单签订
 *
 * @author zeng.junhua
 */
@RestController("cuccOrderSign")
@RequestMapping("/cuccOrderSign")
@Api(tags = {
    "/cuccOrderSign - 订单签订"
})
public class OrderSignController {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Autowired
    private IOrderSignService orderSignService;

    @KiteTransactional
    @ApiOperation(value = "结束工单任务", notes = "结束工单任务")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "dealResult", value = "处理结果", required = true),
        @ApiImplicitParam(name = "failReason", value = "审核不通过原因", required = false),
    })
    @PostMapping("/overOrderTask")
    public DataResult<String> overOrderTask(String dealResult, String failReason) {
        try {
            String sceneInstId = KiteWebContext.getContext().getCurrentSceneInstId();
            String worksheetId = this.querySceneInstService.getExtParameterValue(sceneInstId, "worksheetId");
            String taskId = this.querySceneInstService.getExtParameterValue(sceneInstId, "taskId");
            String taskCode = this.querySceneInstService.getExtParameterValue(sceneInstId, "taskCode");
            Boolean checkAccountModule = false;
            Boolean checkContractModule = false;
            return orderSignService.overOrderTaskSpecial(KiteWebContext.getContext().getCurrentSceneInstId(),
                ContextUtil.getUserId().toString(), ContextUtil.getLoginInfo().getOrgInfo().getOrgId().toString(),worksheetId, taskCode, taskId, dealResult, failReason,
                checkAccountModule, checkContractModule, (CuccContextCustDTO) KiteWebContext.getContext().getCust());
        }
        catch (BssException ex) {
            return ErrorConsts.BUSI_COMMON_ERROR.getResult(ex.getFailCode(), ex.getFailMsg());
        }
    }
}
